home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cexpert.zip / MCH12.LST < prev    next >
File List  |  1990-09-15  |  37KB  |  985 lines

  1. Listing 12-1  Sample Program foe the Inventory Control System
  2.                Prototype Using IQ-200
  3.  
  4.  
  5. #| **********************************************************************
  6.  
  7.         Inventory Control Demo INTERFACE
  8.  
  9. ********************************************************************** |#
  10.  
  11.  
  12. (define-interface 'inventory-control
  13.   :banner " Inventory Control System Demonstration "
  14.   :hot-keys '((224 (start-help)) (238 (quit-interface)) ; f1 and f2
  15.           (#\c-d (dos)) (#\c-r (redraw-screen)) (#\c-m (mouse-initialize)))
  16.   :hot-keys-doc " F1: Help  F10: Quit  C-D: Dos  C-R: Redraw  C-M: Init Mouse "
  17.   :help-file-pathname "c:\\iq200\\examples\\icshelp.txt")
  18.  
  19. ;;;_________________________MODES
  20.  
  21. (define-mode 'inventory-control 'toplevel-mode " Inventory Toplevel "
  22.   '(("Dealership" (run-mode 'dealership-operations-mode))
  23.     ("Warehouse" (run-mode 'warehouse-operations-mode))
  24.     ("System"  (run-mode 'system-operations-mode))
  25.     ("Help" (start-help 'toplevel-mode))
  26.     ("Quit" (quit-interface))))
  27.  
  28. (define-mode 'inventory-control 'Dealership-Operations-Mode " Dealers "
  29.   '(("Inventory" (view-dealer-inventory) :doc "Inventory of a dealer")
  30.     ("Purchase" (request-sale) :doc "Purchase an item")
  31.     ("Order" (order-part) :doc "Enter order from warehouse")
  32.     ("Show Outstanding" (view-outstanding-orders)
  33.             :doc "Show outstanding orders")
  34.     ("Show Processed" (view-processed-orders) :doc "Show processed orders")
  35.     ("Check-Dealers" (check-dealers) :doc "Check dealers for part")))
  36.  
  37. (define-mode 'inventory-control 'warehouse-Operations-Mode " Warehouses "
  38.   '(("View Inventory" (view-warehouse-inventory) :doc "View entire inventory")
  39.     ("Price" (Get-Price) :doc "Get discounted price of part")
  40.     ("Process Orders" (process-orders) :doc "Process Outstanding Orders")
  41.     ("Low Inventories" (check-low-inventories) :doc "Check Low Inventories")
  42.     ("Sales Percentage" (sales-percentage) :doc "Part % of total sales")))
  43.  
  44. (define-mode 'inventory-control 'system-operations-mode " System "
  45.   '(("Redraw" (redraw-screen) :doc "Redraw the screen")
  46.     ("Go to DOS" (dos))))
  47.  
  48.  
  49. ;;;__________________________DEALER PROCEDURES
  50.  
  51. ;;;DEALER INVENTORY
  52. (defprocedure view-dealer-inventory
  53.   (deactivate-rule-set 'basic-rule-set)
  54.   (activate-rule-set 'userint-rules)
  55.   (activate-rule-set 'd-inv-rules)
  56.   (query '(show-dealer-inventory))
  57.   (user-pause))
  58.  
  59.  
  60.  
  61. ;;;PURCHASE
  62. (defprocedure request-sale 
  63.   (deactivate-rule-set 'basic-rule-set)
  64.   (activate-rule-set 'userint-rules)
  65.   (activate-rule-set 'request-rules)
  66.   (query '(request-part))
  67.   (user-pause))
  68.  
  69.  
  70. ;;;ORDER PART
  71. (defprocedure Order-Part
  72.   (deactivate-rule-set 'basic-rule-set)
  73.   (activate-rule-set 'userint-rules)
  74.   (activate-rule-set 'order-rules)
  75.   (query '(order-part))
  76.   (user-pause))
  77.   
  78.  
  79. ;;;VIEW CUSTOMER ORDERS
  80. (defprocedure View-Outstanding-Orders
  81.   (deactivate-rule-set 'basic-rule-set)
  82.   (activate-rule-set 'userint-rules)
  83.   (activate-rule-set 'view-outstanding-rules)
  84.   (query '(view-orders))
  85.   (user-pause))
  86.  
  87.  
  88. ;;;VIEW PROCESSED ORDERS
  89. (defprocedure View-Processed-Orders
  90.   (deactivate-rule-set 'basic-rule-set)
  91.   (activate-rule-set 'userint-rules)
  92.   (activate-rule-set 'view-processed-rules)
  93.   (query '(view-processed-orders))
  94.   (user-pause))
  95.  
  96.  
  97. ;;;CHECK DEALERS
  98. (defprocedure Check-Dealers 
  99.   (deactivate-rule-set 'basic-rule-set)
  100.   (activate-rule-set 'userint-rules)
  101.   (activate-rule-set 'request-rules)
  102.   (query '(dealer-check))
  103.   (user-pause))
  104.  
  105.  
  106. ;;;____________________________WAREHOUSE PROCEDURES
  107.  
  108. ;;;WAREHOUSE INVENTORYè(defprocedure View-Warehouse-Inventory 
  109.   (deactivate-rule-set 'basic-rule-set)
  110.   (activate-rule-set 'userint-rules)
  111.   (activate-rule-set 'w-inv-rules)
  112.   (query '(show-warehouse-inventory))
  113.   (user-pause))
  114.  
  115.  
  116.  
  117. ;;;PRICE 
  118. (defprocedure Get-Price 
  119.   (deactivate-rule-set 'basic-rule-set)
  120.   (activate-rule-set 'userint-rules)
  121.   (activate-rule-set 'price-rules)
  122.   (query '(display-price))
  123.   (user-pause))
  124.  
  125.  
  126. ;;;PROCESS CUSTOMER ORDERS    
  127. (defprocedure Process-Orders 
  128.   (deactivate-rule-set 'basic-rule-set)
  129.   (activate-rule-set 'userint-rules)
  130.   (activate-rule-set 'process-order-rules)
  131.   (stash '(value-of part-found nil))
  132.   (query '(process-orders))
  133.   (user-pause))
  134.  
  135. ;;;LOW INVENTORIES
  136. (defprocedure Check-Low-Inventories 
  137.   (deactivate-rule-set 'basic-rule-set)
  138.   (activate-rule-set 'userint-rules)
  139.   (activate-rule-set 'low-inv-rules)
  140.   (stash '(value-of part-found nil))
  141.   (query '(identify-critical-inventories))
  142.   (user-pause))
  143.  
  144. ;;;SALES PERCENTAGE
  145. (defprocedure Sales-Percentage
  146.   (deactivate-rule-set 'basic-rule-set)
  147.   (activate-rule-set 'userint-rules)
  148.   (activate-rule-set 'percentage-rules)
  149.   (stash '(value-of total-sales 0))
  150.   (stash '(value-of part-sales 0))  
  151.   (query '(get-sales-percentage))
  152.   (user-pause))
  153.  
  154.  
  155.  
  156. #| **********************************************************************
  157.  
  158.         Baldur Host Setup file.
  159.  
  160.  \'s for the c regexpr parser must be doubled (for lisp)
  161. ********************************************************************** |#
  162.  
  163. (define-host 'baldur :phone-number 7329715 :password 'changeme1
  164.          :password2 'changeme2 :os 'dos
  165.          :programs '((dbase3 "c:\\dbase\\") (sql "c:\\sqlbase\\"))
  166.          :toplevel-program 'baldur-server
  167.          :documentation "Hayward AT #1: God of light and Joy (Helios)")
  168. (define-host 'odin :phone-number 7329716 :password 'changeme1
  169.          :password2 'changeme2 :os 'dos
  170.          :programs '((dbase3 "c:\\dbase\\") (sql "c:\\sqlbase\\"))
  171.          :toplevel-program 'baldur-server
  172.          :documentation "Hayward AT #2: Lord of the Gods (Zeus)")
  173. (define-host 'thor :phone-number 3276521 :password 'changeme1
  174.          :password2 'changeme2 :os 'dos
  175.          :programs '((dbase3 "c:\\dbase\\") (sql "c:\\sqlbase\\"))
  176.          :toplevel-program 'baldur-server
  177.          :documentation "Menlo Park AT #1: The War-God (Ares)")
  178. (define-host 'ymer :phone-number 3253860 :password 'changeme1
  179.          :password2 'changeme2 :os 'dos
  180.          :programs '((dbase3 "c:\\dbase\\") (sql "c:\\sqlbase\\"))
  181.          :toplevel-program 'baldur-server
  182.          :documentation "Menlo Park AT #2")
  183. (define-host 'tyr :phone-number 3269106 :password 'changeme1
  184.          :password2 'changeme2 :os 'dos
  185.          :programs '((dbase3 "c:\\dbase\\") (sql "c:\\sqlbase\\"))
  186.          :toplevel-program 'baldur-server
  187.          :documentation "Stanford AT #2: The father of the Gods (Kronos)")
  188. (define-host 'loki :phone-number 3234754 :password 'changeme1
  189.          :password2 'changeme2 :os 'dos
  190.          :programs '((dbase3 "c:\\dbase\\") (sql "c:\\sqlbase\\"))
  191.          :toplevel-program 'baldur-server
  192.          :documentation "Stanford AT #1: The mischievous God")
  193.  
  194.  
  195.  
  196.  
  197. #| **********************************************************************
  198.  
  199.             Inventory Control System Demo OBJECTS
  200.  
  201.   This file contains all the objects for use with the ICS Demo.
  202. ********************************************************************** |#
  203.  
  204. ;;;_________________________RULE SETS
  205.  
  206. (create-rule-set 'dealer-rules)
  207.    (create-rule-set 'request-rules :superset 'dealer-rules)
  208.    (create-rule-set 'order-rules :superset 'dealer-rules)
  209.    (create-rule-set 'd-inv-rules :superset 'dealer-rules)
  210.    (create-rule-set 'view-outstanding-rules :superset 'dealer-rules)
  211.    (create-rule-set 'view-processed-rules :superset 'dealer-rules)
  212.  
  213.  
  214. (create-rule-set 'warehouse-rules)
  215.    (create-rule-set 'w-inv-rules :superset 'warehouse-rules)
  216.    (create-rule-set 'price-rules :superset 'warehouse-rules)
  217.    (create-rule-set 'low-inv-rules :superset 'warehouse-rules)è   (create-rule-set 'process-order-rules :superset 'warehouse-rules)
  218.    (create-rule-set 'percentage-rules :superset 'warehouse-rules)
  219.  
  220. (create-rule-set 'userint-rules)
  221.  
  222. ;;; **********************************************************************
  223. ;;; Rules to determine what parts, dealers, and warehouses exist.
  224.  
  225. ;;; Parts list rules
  226. (create-variable 'parts-list :constraint :list)
  227.  
  228. (create-rule 'get-parts-list :rule-set 'userint-rules
  229.          :premise '(and (format "~%Compiling list of parts...")
  230.                 (set-of ?name
  231.                     (entity ?x is-a san-fran-inv
  232.                         with name = ?name)
  233.                     ?p)
  234.                 (or (not (equal ?p nil))
  235.                 (format "no parts found at San-Fran!!")))
  236.          :action '(stash '(value-of parts-list ?p))
  237.          :conclusion '(get-parts-list ?p))
  238.  
  239. (create-rule 'Part-List :rule-set 'userint-rules
  240.          :premise '(and (cut)
  241.                 (or (value-of parts-list ?list)
  242.                 (get-parts-list ?list)))
  243.          :conclusion '(get-list :part ?list))
  244.  
  245. ;;; Warehouse & Dealer list rules
  246.  
  247. (create-rule 'Warehouse-List :rule-set 'userint-rules
  248.          :premise '(set-of ?x (entity ?x is-a warehouse) ?list)
  249.          :conclusion '(get-list :warehouse ?list))
  250. (create-rule 'Dealer-List :rule-set 'userint-rules
  251.          :premise '(set-of ?x (entity ?x is-a dealer) ?list)
  252.          :conclusion '(get-list :dealer ?list))
  253.  
  254. ;;;_________________________SPECIAL I/O RULES
  255.  
  256. ;;; Supports types of :dealer :warehouse :part
  257. ;;; (achieve '(pick-value "Enter dealer to use" :dealer ?answer))
  258.  
  259. (create-rule 'pick-value :rule-set 'userint-rules
  260.      :premise '(and (get-list ?type ?list)
  261.             (cut)
  262.             (menu-choose ?list ?string ?result))
  263.      :conclusion '(pick-value ?string ?type ?result))
  264.  
  265. ;;;**********************************************************************
  266. ;;;                      DEALERSHIP OPERATION RULES                     *
  267. ;;;**********************************************************************
  268.  
  269. ;;;_________________________DEALER INVENTORY
  270.  
  271. (create-rule 'display-dealer-inv :rule-set 'd-inv-rules
  272.      :premise '(and (pick-value "Enter dealer to use" :dealer ?dealer)
  273.                 (entity ?dealer is-a dealer with inventory = ?inv)
  274.             (entity ?ent is-a ?inv with name = ?part-name
  275.                  with cil = ?cil)
  276.             (format "~%Part-Name: ~A, Number in Stock: ~A"
  277.                 ?part-name ?cil)
  278.              (fail))
  279.       :conclusion '(show-dealer-inventory))
  280.  
  281. ;;;_________________________REQUEST SALE
  282.  
  283. (create-rule 'new-request :rule-set 'request-rules
  284.       :premise '(and (pick-value "Enter dealer to use" :dealer ?dealer)
  285.              (or (and (remote-dealer ?dealer) (cut)
  286.               (format "~%Sorry, ~A is a foreign dealer and cannot"
  287.                       ?dealer)
  288.                   (format "~%accept purchases at this location.")
  289.                   (fail))
  290.              (succeed))
  291.              (pick-value "Enter part to use" :part ?part-name)
  292.              (menu-input "Enter number desired" :integer ?num)
  293.              (format "~%Looking in ~A's inventory for ~A"
  294.                  ?dealer ?part-name)
  295.              (request ?dealer ?part-name ?num))
  296.      :conclusion '(request-part))
  297.  
  298. (create-rule 'process-request :rule-set 'request-rules
  299.          :premise '(or (and (num-available? ?curr-deal ?part-name ?num)
  300.                 (format "~%Part ~A is in stock in ~A.  Reducing inventory..."
  301.                     ?part-name ?curr-deal)
  302.                 (reduce-inv ?curr-deal ?part-name ?num))
  303.                (format "~%Part ~A not available at ~A.~%Try checking other dealers or ordering part."
  304.                    ?part-name ?curr-deal))
  305.          :conclusion '(request ?curr-deal ?part-name ?num))
  306.  
  307. (create-rule 'remote-dealer :rule-set 'request-rules
  308.          :premise '(and (inventory ?dealer ?inv)
  309.                 (entity ?ks is-a knowledge-source
  310.                     with class-defined = ?inv))
  311.          :conclusion '(remote-dealer ?dealer))
  312.  
  313. (create-rule 'reduce-inventory :rule-set 'request-rules
  314.      :premise '(and (inventory ?curr-deal ?inv)
  315.             (entity ?ent is-a ?inv with name = ?part-name
  316.                 with cil = ?old)
  317.             (- ?old ?num ?new)
  318.             (format "~%Inventory at ~A reduced from ~A to ~A."
  319.                 ?curr-deal ?old ?new))
  320.      :conclusion '(reduce-inv ?curr-deal ?part-name ?num)
  321.      :action '(stash '(cil ?ent ?new)))
  322.  
  323. (create-rule 'Available :rule-set 'request-rules
  324.      :premise '(and (inventory ?source ?inv)
  325.             (entity ?ent is-a ?inv with name = ?part-name
  326.                 with cil = ?cil)
  327.             (<= ?number ?cil))
  328.      :conclusion  '(num-available? ?source ?part-name ?number))
  329.  
  330.  
  331. ;;;_________________________ORDER PART
  332.  
  333. ;;; Top level backward chaining rule.
  334. (create-rule 'order-new-part :rule-set 'order-rules
  335.       :premise '(and (pick-value "From which dealer?" :dealer ?curr-deal)
  336.              (pick-value "Choose part to order" :part ?part-name)
  337.              (choose-values
  338.                ((num :prompt "Number to order: " :constraint :integer
  339.                  :mandatory? t)
  340.             (cust :prompt "New customer name: " :constraint :name
  341.                   :mandatory? t)
  342.             (date :prompt "Order date: " :constraint :date
  343.                   :mandatory? t))
  344.                "Enter Customer information"
  345.                ?num ?cust ?date)
  346.              (print-arrival-info ?cust ?part-name))
  347.      :conclusion '(order-part)
  348.      :action '(create-entity '?cust :class 'Stanford-Custs
  349.                  :name '?cust :dealer '?curr-deal
  350.                  :part '?part-name :quantity '?num
  351.                  :order-date '?date))
  352.  
  353. ;;; Gets arrival information from the warehouse.
  354. (create-rule 'calc-days-to-arrival :rule-set 'order-rules
  355.          :premise '(and (entity ?ware is-a warehouse)
  356.                 (format "~%Looking for a warehouse that stocks ~A"
  357.                     ?part-name)
  358.                 (inventory ?ware ?inv)
  359.                 (entity ?ent is-a ?inv with name = ?part-name
  360.                     with order-time = ?days)
  361.                 (format "~%Warehouse ~A has the part.  Computing arrival certainty" ?ware)
  362.                 (or (adjust-certainty ?part-name) (succeed)))
  363.          :conclusion '(days-to-arrival ?part-name ?days)
  364.          :certainty 0.9)
  365.  
  366. (create-rule 'print-arrival-info :rule-set 'order-rules
  367.      :premise '(and (certainty-of (days-to-arrival ?part-name ?days) ?cf)
  368.             (format "~%The certainty of the order for ~A arriving in ~A days is ~A." ?cust ?days ?cf))
  369.      :conclusion '(print-arrival-info ?cust ?part-name))
  370.  
  371. ;;; Adjustment for unreliable part deliveries.
  372. (create-variable 'unreliable-parts :value '(parking_brake cooling_fan)
  373.          :constraint :list 
  374.          :documentation "Parts whose delivery is more uncertain")
  375.  
  376. (create-rule 'adjust-certainty :rule-set 'order-rules
  377.          :premise '(and (value-of unreliable-parts ?up)
  378.                 (eval (member '?part-name '?up) ?result)
  379.                 (not (equal ?result nil))
  380.                 (format "~%Delivery of part ~A found unreliable; adjusting arrival certainty." ?part-name))
  381.          :conclusion '(adjust-certainty ?part-name)è         :certainty .7)
  382.  
  383. ;;;_________________________VIEW CUSTOMER ORDERS
  384.  
  385. ;;;need OR rule for no order condition
  386. (create-rule 'view-order :rule-set 'view-outstanding-rules
  387.     :premise '(and (pick-value "Which dealer's customers?" :dealer ?deal)
  388.            (entity ?deal is-a dealer with customers = ?deal-custs)
  389.            (entity ?cust-ent is-a ?deal-custs with name = ?n
  390.                with part = ?pd)
  391.            (entity ?cust-ent is-a ?deal-custs with quantity = ?nd
  392.                with order-date = ?od)
  393.            (format "~%Customer: ~A, Part: ~A, Quantity: ~A, Ordered: ~A" ?n ?pd ?nd ?od)
  394.            (fail))
  395.       :conclusion '(view-orders))
  396.  
  397. ;;;_________________________VIEW PROCESSED ORDERS
  398.  
  399. (create-rule 'view-processed-order :rule-set 'view-processed-rules
  400.     :premise '(and (pick-value "Which dealer to view orders from?" :dealer
  401.                    ?dealer)
  402.            (or (processed-order ?dealer ?cust ?part-name ?num)
  403.                (and (format "~%No orders processed for ~A" ?dealer)
  404.                 (cut) (fail)))
  405.            (format "~%Order Processed for ~A:  Cust: ~A,  Part: ~A, Number: ~A." ?dealer ?cust ?part-name ?num)
  406.            (fail))
  407.       :conclusion '(view-processed-orders))
  408.  
  409. ;;;_________________________CHECK DEALERS
  410.  
  411. (create-rule 'Dealer-Check :rule-set 'request-rules
  412.          :premise '(and (pick-value "Enter part to check" :part ?part-name)
  413.                 (menu-input "Enter number desired" :integer ?num)
  414.                 (format "~%COMMENCING FOREIGN DEALER INQUIRY...")
  415.                 (entity ?dealer is-a dealer)
  416.                 (format "~%~A..." ?dealer)
  417.                 (or (and (num-available? ?dealer ?part-name ?num)
  418.                      (format "has ~A ~As in stock" ?num ?part-name))
  419.                 (format "does not have enough ~As" ?part-name))
  420.                 (fail))
  421.          :conclusion '(dealer-check))
  422.  
  423. ;;;**********************************************************************
  424. ;;;                      WAREHOUSE OPERATION RULES                      *
  425. ;;;**********************************************************************
  426.  
  427.  
  428.  
  429.  
  430. ;;;_________________________WAREHOUSE INVENTORY
  431.  
  432. (create-rule 'display-warehouse-inventories :rule-set 'w-inv-rules
  433.      :premise '(and (pick-value "Choose warehouse to display"
  434.                 :warehouse ?ware)
  435.             (inventory ?ware ?inv)
  436.              (entity ?ent is-a ?inv with name = ?part-name
  437.                  with cost = ?cost with discount = ?discount)
  438.              (format "~%Part-Name: ~A, Cost: ~A, Discount: ~A."
  439.                  ?part-name ?cost ?discount)
  440.              (fail))
  441.       :conclusion '(show-warehouse-inventory))
  442.  
  443.  
  444. ;;;_________________________GET PRICE 
  445.  
  446. (create-rule 'display-price :rule-set 'price-rules
  447.      :premise '(and (pick-value "Enter warehouse to use" :warehouse ?ware)
  448.             (pick-value "Pricing for which part?" :part ?part-name)
  449.             (format "~%Requesting pricing information from warehouse")
  450.             (or (and (inventory ?ware ?inv)
  451.               (entity ?ware-ent is-a ?inv with name = ?part-name
  452.                   with cost = ?cost with discount = ?discount)
  453.               (true-cost ?cost ?discount ?true-cost)
  454.               (format "~%Current price of ~A (including $~A discount): $~A"
  455.                   ?part-name ?discount ?true-cost))
  456.             (format "~%Pricing information on ~A not found."
  457.                 ?part-name)))
  458.      :conclusion '(display-price))
  459.  
  460. (create-rule 'True-Cost :rule-set 'price-rules   
  461.      :premise '(and (format "~%Evaluating discount costs")
  462.             (- ?cost ?discount ?tcost))
  463.      :conclusion '(true-cost ?cost ?discount ?tcost))
  464.  
  465. ;;;_________________________PROCESS CUSTOMER ORDERS
  466.  
  467. ;;; this will transfer a part for every customer
  468. (create-rule 'Process-Order :rule-set 'process-order-rules
  469.      :premise '(and (pick-value "Enter warehouse to process orders"
  470.                 :warehouse ?ware)
  471.             (subclass ?customer customer)
  472.             (entity ?cust is-a ?customer with name = ?name
  473.                 with part = ?part-name)
  474.             (entity ?cust is-a ?customer with dealer = ?dealer
  475.                 with quantity = ?num)
  476.             (format "~%Transfer needed for customer ~A:" ?name)
  477.             (format "~%  ~A ~A from ~A to ~A"
  478.                 ?num ?part-name ?ware ?dealer)
  479.             (transfer ?part-name ?num ?cust ?ware ?dealer)
  480.             (eval (stash '(value-of part-found t)))
  481.             (fail))
  482.      :conclusion '(process-orders))
  483.  
  484. (create-rule 'notify-no-orders-to-process :rule-set 'process-order-rules
  485.      :premise '(and (value-of part-found nil)
  486.             (format "~%There are no more current orders."))
  487.      :conclusion '(process-orders)
  488.      :priority 5)
  489.  
  490. (create-rule 'transfer-from-ware/delete-cust :rule-set 'process-order-rulesè    :premise '(and (inventory ?ware ?ware-inv)
  491.            (or (and (entity ?dealer is-a dealer)
  492.                 (not (remote-dealer ?dealer)))
  493.                (and (format "~%  Dealer ~A does not exist locally"
  494.                     ?dealer)
  495.                 (fail)))
  496.            (or (entity ?part-inv is-a ?ware-inv with name = ?part-name
  497.                with cil = ?cil)
  498.                (and (format "~%  Could not confirm that warehouse ~A stocks this part"
  499.                     ?ware) (fail)))
  500.            (or (and (<= ?num ?cil)
  501.                 (- ?cil ?num ?new-cil)
  502.                 (format "~%  ~A ~A transfered to ~A for ~A."
  503.                     ?num ?part-name ?dealer ?cust))
  504.                (and (format "~%  Transfer unsuccessful, insufficient supply at ~A" ?ware)
  505.                  (fail))))
  506.     :conclusion '(transfer ?part-name ?num ?cust ?ware ?dealer)
  507.     :action
  508.     '(do-all (delete-entity '?cust)
  509.          (stash '(and (cil ?part-inv ?new-cil) ; only do this if local!!
  510.               (processed-order ?dealer ?cust ?part-name ?num)))))
  511.  
  512. ;;;_________________________LOW INVENTORIES
  513.  
  514. (create-variable 'part-found :constraint :boolean)
  515. (create-variable 'threshold-inventory :value .25 :constraint :fraction)
  516.  
  517. (create-rule 'quarter-inv :rule-set 'low-inv-rules
  518.      :premise '(and (pick-value "Enter warehouse to use" :warehouse ?ware)
  519.             (value-of threshold-inventory ?thres)
  520.             (format "~%Parts for warehouse ~A." ?ware)
  521.             (inventory ?ware ?inv)
  522.             (entity ?ware-ent is-a ?inv with name = ?name
  523.                 with cil = ?cil with oil = ?oil)
  524.             (/ ?cil ?oil ?ratio)
  525.             (< ?ratio ?thres)
  526.             (* ?ratio 200 ?%ratio)
  527.             (eval (stash '(value-of part-found t)))
  528.             (format "~%Critical inventory on ~A:" ?name)
  529.             (format "~%  Current inventory is ~A% of optimal" ?%ratio)
  530.             (fail))
  531.      :conclusion '(identify-critical-inventories))
  532.  
  533. (create-rule 'notify-no-low-invs :rule-set 'low-inv-rules
  534.      :premise '(and (value-of part-found nil)
  535.             (format "~%No parts with critically low inventories."))
  536.      :conclusion '(identify-critical-inventories)
  537.      :priority 5)
  538.  
  539. ;;;_________________________SALES PERCENTAGE
  540.  
  541. (create-variable 'total-sales :constraint :number)
  542. (create-variable 'part-sales :constraint :number)
  543.  
  544. (create-rule 'calc-sales-init :rule-set 'percentage-rulesè     :premise '(and (pick-value "Enter warehouse to use" :warehouse ?ware)
  545.             (pick-value "Enter part to use" :part ?part-name)
  546.             (format "~%Initializing warehouse query for ~A at ~A."
  547.                 ?part-name ?ware)
  548.             (get-part-totals ?part-name ?ware)
  549.             (calc-sales-perc ?part-name))
  550.      :conclusion '(get-sales-percentage))
  551.  
  552. (create-rule 'calc-stats :rule-set 'percentage-rules
  553.      :premise '(or (and (sales-records ?ware ?sr)
  554.             (entity ?ent is-a ?sr with total-sale = ?total-sale)
  555.             (add-value-to-variable total-sales ?total-sale)
  556.             ; if the part is the one we want, add its sales
  557.                 (part ?ent ?part-name)
  558.             (add-value-to-variable part-sales ?total-sale)
  559.             (fail))
  560.            (succeed))
  561.      :conclusion '(get-part-totals ?part-name ?ware))
  562.  
  563. (create-rule 'calc-sales-percentage :rule-set 'percentage-rules
  564.      :premise '(and (value-of total-sales ?total-sales)
  565.             (value-of part-sales ?part-sales)
  566.             (not (= ?total-sales 0))
  567.             (eval (* 200 (/ ?part-sales ?total-sales)) ?per)
  568.             (format "~%Sales statistics on ~A: " ?part-name)
  569.             (format "~%Part Sales = $~A.  Total Sales = $~A"
  570.                 ?part-sales ?total-sales)
  571.             (format "~%Percentage of Total Sales = ~A%" ?per))
  572.      :conclusion '(calc-sales-perc ?part-name))
  573.  
  574. (create-rule 'notify-part-not-found :rule-set 'percentage-rules
  575.      :premise '(format "~%No sales for part requested.")
  576.      :conclusion '(get-sales-percentage)
  577.      :priority 5)
  578.  
  579. (create-rule 'add-value-to-variable :rule-set 'percentage-rules
  580.      :premise '(and (value-of ?variable ?old)
  581.             (+ ?old ?value ?new))
  582.      :conclusion '(add-value-to-variable ?variable ?value)
  583.      :action '(stash '(value-of ?variable ?new)))
  584.  
  585. ;;;THE END
  586.  
  587.  
  588. #| **********************************************************************
  589.  
  590.      Class and Knowledge Source definitions for ICS demo.
  591.  
  592. **********************************************************************|#
  593.  
  594. ;;; Class definitions for dealer and warehouse inventories on car parts.
  595. (create-class 'Location :documentation "Represents a location"
  596.           :slots '((address :constraint :string)
  597.                (phone :constraint :number)
  598.                (inventory :constraint (:subclass inventory))))
  599. (create-class 'Warehouse :documentation "Represents an actual warehouse"
  600.           :superclass 'location
  601.           :slots '((sales-records :constraint (:subclass sales-records))))
  602. (create-class 'Dealer :documentation "Represents an actual dealer"
  603.           :superclass 'location
  604.           :slots '((customers :constraint (:subclass customer))))
  605.  
  606. (create-class 'Inventory :documentation "Inventory information on a part"
  607.           :slots '((name :constraint :name)          ; part name
  608.                (cil :constraint :integer)     ;current invent level
  609.                (oil :constraint :integer)))   ;optimal invent level
  610.  
  611. (create-class 'Warehouse-Inv :superclass 'inventory
  612.           :documentation "A Warehouse inventory on a part"
  613.           :slots '((cost :constraint :number)
  614.                (discount :constraint :number)
  615.                (min-order :constraint :integer)
  616.                (order-time :constraint :integer)))
  617.  
  618. (create-class 'Dealer-Inv :superclass 'inventory
  619.           :documentation "A dealer inventory on a part")
  620.  
  621. (create-class 'Customer :documentation "Dealership customer"
  622.      :slots '((dealer :constraint :name)
  623.           (name :constraint :name)
  624.           (part :constraint :name)  
  625.           (quantity :constraint :number :when-needed 1)
  626.           (order-date :constraint :date) 
  627.           (time :constraint :number)))
  628.  
  629. (create-class 'Sales-Records)
  630.  
  631. ;;; **********************************************************************
  632. ;;; Let's create a warehouse
  633.  
  634. (read-lotus123-class 'San-Fran-Sales-Records
  635.               :filename "c:\\iq200\\examples\\ware.wk1"
  636.               :superclass 'Sales-Records
  637.               :slot-names-row 0
  638.               :deleted-rows '(1)
  639.               :deleted-columns '(1))
  640.  
  641. (create-class 'San-Fran-Inv :superclass 'warehouse-inv
  642.           :documentation "Inventory of parts for San Francisco Warehouse")
  643. (define-knowledge-source 'San-FranKS :host :local
  644.   :program 'dbase3
  645.   :filename "c:\\iq200\\examples\\ware.dbf"
  646.   :class-defined 'San-Fran-Inv
  647.   :slot-with-entity-name nil
  648.   :name-constrained-slots '(name)
  649.   :slot-name-translations '((min-order min_ord) (order-time order_time)))
  650.  
  651. #|
  652. (read-dbase3-class 'San-Fran-Inv
  653.            :superclass 'warehouse-invè           :filename "c:\\iq200\\examples\\ware.dbf"
  654.            :slot-with-entity-name nil
  655.            :name-constrained-slots '(name)
  656.            :slot-name-translations '((min-order min_ord) (order-time order_time)))
  657. |#
  658. (create-warehouse 'San-Fran :inventory 'san-fran-inv :phone 7329715
  659.           :address "230 Geary St."
  660.           :sales-records 'san-fran-sales-records)
  661.  
  662. ;;; **********************************************************************
  663. ;;; Let's create some dealers
  664.  
  665. ;;; Stanford dealer
  666. (read-dbase3-class 'Stanford-Inv
  667.            :filename "c:\\iq200\\examples\\dealer1.dbf"
  668.            :superclass 'dealer-inv
  669.            :documentation "Stanford Inventory")
  670.  
  671. ;;; local customers
  672. (read-dbase3-class 'Stanford-Custs
  673.             :filename "c:\\iq200\\examples\\cust1.dbf"
  674.             :superclass 'customer
  675.             :slot-with-entity-name 'name
  676.             :name-constrained-slots '(name dealer part)
  677.             :slot-name-translations '((order-date order_date)))
  678.  
  679. (create-dealer 'stanford :inventory 'stanford-inv :phone 3269106
  680.            :customers 'stanford-custs)
  681.  
  682. ;;; Palo Alto dealer
  683.  
  684. (create-class 'Palo-Alto-Inv :superclass 'dealer-inv)
  685. (define-knowledge-source 'Palo-AltoKS :host :local ; 'odin
  686.   :program 'dbase3
  687.   :filename "c:\\iq200\\examples\\dealer2.dbf"
  688.   :name-constrained-slots '(name)
  689.   :class-defined 'Palo-Alto-Inv)
  690.  
  691. (create-class 'Palo-Alto-Custs :superclass 'customer)
  692. (define-knowledge-source 'Palo-Alto-CustKS :host :local  ; 'baldur
  693.   :program 'dbase3
  694.   :filename "c:\\iq200\\examples\\cust2.dbf"
  695.   :slot-with-entity-name 'name
  696.   :class-defined 'Palo-Alto-Custs
  697.   :name-constrained-slots '(dealer name part)
  698.   :slot-name-translations '((order-date order_date)))
  699.  
  700. (create-dealer 'palo-alto :inventory 'palo-alto-inv :phone 3276521
  701.            :customers 'palo-alto-custs)
  702.  
  703. ;;; Hayward Dealer
  704. (create-class 'Hayward-Inv :superclass 'dealer-inv)
  705. (define-knowledge-source 'HaywardKS :host :local
  706.   :program 'dbase3
  707.   :filename "c:\\iq200\\examples\\dealer3.dbf"
  708.   :name-constrained-slots '(name)
  709.   :class-defined 'Hayward-Inv)
  710.  
  711. (create-class 'Hayward-Custs :superclass 'customer)
  712. (define-knowledge-source 'Hayward-custKS :host :local
  713.   :program 'dbase3
  714.   :filename "c:\\iq200\\examples\\cust3.dbf"
  715.   :slot-with-entity-name 'name
  716.   :name-constrained-slots '(dealer name part)
  717.   :class-defined 'Hayward-Custs
  718.   :slot-name-translations '((order-date order_date)))
  719.  
  720. (create-dealer 'hayward :inventory 'hayward-inv :phone 7329723
  721.            :customers 'hayward-custs)
  722.  
  723.  
  724.  
  725.  
  726. Title: 
  727. inventory-control
  728. Text:
  729.  
  730. Welcome to the Mazda Inventory Control System (ICS).  This demo serves
  731. as an introduction to IQ200 - the User Interface, Developers
  732. Interface, and Communications.  The main function of the ICS is
  733. to maintain inventories of automobile parts at a number of
  734. dealerships and warehouses. 
  735.  
  736. For assistance with the setup (loading demo files, setting up knowledge
  737. sources, hosts), see subsection SETUP.
  738.  
  739. Sub-Topics:
  740. (Setup Dealership Warehouse System Help Quit)
  741. Mode: 
  742. toplevel-mode
  743.  
  744. Title:
  745. inventory-control.Setup 
  746. Text: 
  747.  
  748. There are 4 files to be loaded before the demo can be used:
  749. ICSINT1.BPL, ICSHOST2.BPL, ICSOBJ3.BPL, and ICSKS4.BPL.  The
  750. files can be in any directory.  They should be loaded IN THE
  751. ORDER OF THEIR NUMBERS by using the IQ200 interface command Read
  752. (BPL).  Otherwise, the file ICS.BPL can be loaded to do the loading
  753. automatically.  The KS and HOST files may need to be
  754. edited to proper operation.  The HOST file contains all the
  755. functions for setting defining external communications systems -
  756. computer modem lines, operating systems etc.  You may want to change
  757. the NAME, PHONE NUMBER, and DBASE DIRECTORY of these hosts to
  758. represent the computers you will be working with.  The KS file
  759. contains the descriptions of the sources (files external or
  760. local) you will be using for the dealerships and warehouse.
  761. Currently, all the knowledge sources are set up to use dBASE III
  762. files from the LOCAL computer.  For these knowledge sources, you
  763. may wish to change the FILENAME slot to represent the location of
  764. the files.  In order to make the knowledge sources remote for
  765. communications demonstration, change the HOST specifications of
  766. the individual knowledge sources (one of Hosts defined in
  767. ICSHOST2).  In addition, you may wish to change the DB-FILE and
  768. CLASS-DEFINED to represent the names used for a particular
  769. situation.  NOTE: the files ICSINT1 and ICSOBJ3 should never be
  770. changed; neither should any other slots than mentioned above;
  771. neither should any contents of the dbase and lotus files
  772. originally provided.
  773.   
  774.  
  775. Title:
  776. inventory-control.Dealership
  777. Text:
  778.  
  779. The DEALERSHIP commands affect changes in the local dealership,
  780. and gather knowledge from the external dealers and warehouses.
  781. Each dealership maintains a limited selection (both in kind and
  782. quantity) of the parts which are available at the warehouse.
  783. This small inventory is used to satisfy the request of individual
  784. customers at the dealership; if a part is not available (either
  785. in kind or quantity) then the part can be ordered from the
  786. warehouse, or other dealers can be checked for the part.
  787.  
  788. Sub-Topics:
  789. (Inventory Purchase Order Show-Outstanding Show-Processed Check-Dealers)
  790. Mode: 
  791. dealership-operations-mode
  792.  
  793. Title:
  794. inventory-control.Dealership.Inventory
  795. Text:
  796.  
  797. The inventory command has one input, the dealership to be used
  798. for the command, and a listed output, the current inventory of
  799. that dealer (part names and number in stock).  If the dealer
  800. chosen is an external source, the communications system will
  801. automatically call up the proper host and obtain the information.
  802. Note current inventories at a number of dealers before using
  803. other commands (checking purposes).
  804.  
  805.  
  806. Title:
  807. inventory-control.Dealership.Purchase
  808. Text:
  809.  
  810. Purchase is to discover if a part is available at a dealer in a
  811. certain quantity.  Its inputs are: dealer to use, part desired,
  812. and number desired.  The output depends on a) if the dealer
  813. selected is local (cannot make purchases from remote dealers);
  814. b) if the part is in stock in the proper quantity at the
  815. dealership requested, the stock at the dealership is reduced and
  816. the user is notified of the sale c) if the part is not in stock,
  817. the user is asked to order the part (use ORDER command) or check
  818. other dealers (CHECK-DEALERS).  Note reduction in stock after a
  819. successful sale using the INVENTORY command.
  820.  
  821.  
  822. Title:
  823. inventory-control.Dealership.Order
  824. Text:
  825.  
  826. Order is used to tell the warehouse that a dealership REQUESTS a
  827. new supply of a certain part.  It is equivalent to writing a
  828. letter to the warehouse - no reductions in inventory, sales, etc.
  829. will occur upon completion of the procedure.  The new order is
  830. considered OUTSTANDING (as opposed to those processed by the
  831. warehouse).  Inputs are dealer, part, num desired, order name,
  832. and date.  Output is the creation of a customer internal to
  833. Iq200.
  834.  
  835.  
  836. Title:
  837. inventory-control.Dealership.Show-Outstanding
  838. Text:
  839.  
  840. Show-Outstanding merely displays the outstanding (non-processed)
  841. orders at a certain dealer.  Name of order, date, part, and
  842. number are displayed.  This list will be empty if all orders have
  843. been processed.
  844.  
  845.  
  846. Title:
  847. inventory-control.Dealership.Show-Processed
  848. Text:
  849.  
  850. This command shows all the orders which have been processed by
  851. the warehouse.  It will be the empty if their are no orders or
  852. none of the available orders have been processed.  Input is the
  853. dealership whose orders you wish to display.
  854.  
  855.  
  856. Title:
  857. inventory-control.Dealership.Check-Dealers
  858. Text:
  859.  
  860. The Check-Dealer command is useful for discovering which DEALERS
  861. have a certain part in stock.  This is just a lookup procedure.
  862. The inputs are the part name and the quantity desired, while the
  863. output is a list of all dealers which have the quantity desired
  864. of the part in stock.  When using communications, this command
  865. will sequentially call all of the hosts which are serving as
  866. dealers.
  867.  
  868.  
  869. Title:
  870. inventory-control.Warehouse      
  871. Text:
  872. èThe WAREHOUSE commands operate on either local or non-local
  873. warehouse inventories.  Warehouse inventories are much larger
  874. than dealer inventories, both in diversity of parts and in number
  875. available.  The warehouse obviously serves as a backup for the
  876. dealers; if no dealership has a certain part, the part can be
  877. ordered by the warehouse.  The warehouse also serves two other
  878. functions: the establishment of current pricing information for
  879. all dealerships, and the calculation of sales statistics on
  880. certain parts and groups of parts.
  881.  
  882. Sub-Topics:
  883. (View-Inventory Price Process-Orders Low-Inventories)
  884. Mode: 
  885. warehouse-operations-mode
  886.  
  887. Title:
  888. inventory-control.Warehouse.View-Inventory
  889. Text:
  890.  
  891. View-Inventory is a lookup command.  It is used to display the
  892. current inventory of the warehouse at any period in time.  The
  893. command will request the warehouse to use, and will exit by
  894. displaying a list of all parts and their current prices.
  895.  
  896.  
  897. Title:
  898. inventory-control.Warehouse.Price
  899. Text:
  900.  
  901. PRICE obtains the current price of a part from the warehouse.  It
  902. will then attempt to evaluate any discounts on the part and
  903. display the "true" cost of the part.  Prices are shown for
  904. quantity of one.
  905.  
  906.  
  907. Title:
  908. inventory-control.Warehouse.Process-Orders
  909. Text:
  910.  
  911. Process-orders is used to satisfy the orders of the dealers by
  912. transferring supplies of parts.  For each order which is
  913. outstanding at the dealers, the warehouse will attempt to reduce
  914. its own inventory on the part and send the dealers the correct
  915. quantity of the part.  If the correct quantity is not available
  916. at the warehouse, the order cannot be processed, and nothing
  917. happens other than a notice to this effect.  If the correct
  918. quantity is available, the warehouse will reduce its own
  919. inventory (note only possible if LOCAL; cant change external),
  920. delete the customer entity, and store information about the
  921. processed order.  NOTE: the dealership inventory on the part is
  922. NOT affected - the order is PROCESSED - meaning the order is
  923. ready for pickup by the customer, and can be view using the
  924. dealership SHOW-PROCESSED command.
  925.  
  926. Title:
  927. inventory-control.Warehouse.Low-Inventories
  928. Text:
  929.  
  930. Low inventories is a command which attempts to notify the user
  931. about critically low inventories at the warehouse.  The procedure
  932. is to sequentially calculate the inventory ratio
  933. (current-inv-level over optimal-inv-level) and display any parts
  934. which are below 0.25.  Quarter inventory is therefore the
  935. criteria for low inventory.  The command does not attempt to
  936. alleviate any critical inventories.
  937.  
  938.  
  939. Title:
  940. inventory-control.System
  941. Text:
  942.  
  943. System commands are commands for running the demonstration.
  944. Commands are available for redrawing the screen, displaying the
  945. rule structure, and exiting to Dos.
  946.  
  947. Sub-Topics:
  948. (Redraw Go-To-Dos)
  949. Mode: 
  950. system-operations-mode
  951.  
  952. Title:
  953. inventory-control.System.Redraw
  954. Text:
  955.  
  956. Redraws the screen.  Also available at any time by pressing C-R.
  957.  
  958.  
  959. Title:
  960. inventory-control.System.Go-To-Dos
  961. Text:
  962.  
  963. Exits temporarily to DOS.  Type EXIT at the DOS prompt to return
  964. to the demonstration.  Quick exit to DOS is also provided by
  965. pressing C-X C-D.
  966.  
  967.  
  968. Title:
  969. inventory-control.Help      
  970. Text:
  971.  
  972. Help is available using the Help command, and by pressing the
  973. <F1> function key.  Help from the command line is from top-level.
  974. Help from <F1> is context sensitive (depending on the current
  975. mode of operation).
  976.  
  977.  
  978. Title:
  979. inventory-control.Quit      
  980. Text:
  981.  
  982. The QUIT command is used to exit the demonstration and return to
  983. IQ200.  
  984.  
  985.